home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-15 | 7.7 KB | 228 lines | [TEXT/MPS ] |
- //
- // Atom2.c
- //
- //
- // atom2.c
- //
- // Demonstration of a format2 action atom.
- //
- // A dialog is provided that allows the user to select
- // the return value for the action atom.
- //
- // Scriptwriters should be aware that the return values
- // and the actions that they invoke from the installer
- // are different depending on which format of action atom
- // is being used.
- //
- // It is recommended that the constants
- // 'kActionAtomResultFatalError' <= -1
- // 'kActionAtomResultContinue' <= 0
- // 'kActionAtomResultCancel' <= 1
- // be used when working with format2 action atoms.
- // These constants are defined in "ActionAtomHeader.h"
- // and are designed for use with format2 action atoms.
- //
- // NOTE: Displaying dialogs from within an action atom
- // can enhance or detract from the user experience, and
- // should be done with consideration to the overall flow
- // of installation. A good rule of thumb is to never display
- // dialogs from an action atom unless absolutely necessary.
- // This example is very useful in demonstrating behavior of
- // the installer in regards to return values from an action
- // atom, but is a terrible example of user interface design.
- //
- // mark young • 08/18/94
- //
- // Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
- //
-
-
- #include <Traps.h>
- #include <Types.h>
- #include <dialogs.h>
- #include <TextUtils.h>
-
- // these lines have been added for Wasabi Installer Debugger support
- #include "CallbackDispatcherHeader.h"
- #include "ActionHandlerHeader.h"
- #include "InstallerMemoryFuncsHeader.h"
-
- // this line replaces #include "ActionAtomIntf.h" used in Installer 3.x action atoms
- #include "ActionAtomHeader.h"
-
- // this is needed for highliting the default button in dialog
- pascal OSErr SetDialogDefaultItem ( DialogPtr theDialog,
- short newItem ) = {0x303C,0x0304,0xAA68};
-
- // this is used to print one line out to the Wasabi Installer Debugger
- void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 );
-
- // this function sends text out to the Wasabi Installer Debugger
- void RegisterScriptAction( CallBackProcPtr pCallBackProcPtr,
- short actionClassID,
- short actionIdentifier,
- void* param0,
- void* param1,
- void* param2,
- void* param3,
- void* resultPtr );
-
- // print the parameter block record information to Wasabi Installer Debugger
- void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr );
-
- // NOTE: The name of this function 'ActionAtomFormat2' should
- // match that specified in the -m option for the line in the
- // makefile that compiles this action atom.
- ActionAtomResult ActionAtomFormat2( ActionAtom2PBPtr atomRecPtr )
- {
-
- DialogPtr theDialog; // for dialog
- OSErr theOSError = 0; // for errors
-
- short theItemHit; // gets user response from ModalDialog()
- short iType; // gets control type from GetDItem()
- Handle iHandle; // gets control handle from GetDItem()
- Rect iRect; // gets control rect from GetDItem()
-
- short currRadioButton = 2; // current selected radio button
- short gettingUserResponse = true; // flag for while loop
-
- short theStatus = 0; // value to return from function
-
- // print the parameter block record information to Wasabi Installer Debugger
- PrintAAParamBlock( atomRecPtr );
-
- // retrieve DLOG/DITL 130 from compiled resource script
- theDialog = GetNewDialog( 130, nil, (WindowPtr) -1 );
-
- // activate OK button when enter or return key is pressed
- theOSError = SetDialogDefaultItem( theDialog, 1 );
-
- // set up the radio button group ( controls 2 - 4 )
- GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // select the new dialog
- SelectWindow( (WindowPtr) theDialog );
-
- // show the new dialog
- ShowWindow( (WindowPtr) theDialog );
-
- // keep getting response from user until
- // the OK is activated in the new dialog
- gettingUserResponse = true;
- while ( gettingUserResponse )
- {
- // get user selection from the new dialog
- ModalDialog( nil, &theItemHit );
-
- switch ( theItemHit )
- {
- // first control is the OK key
- case( 1 ) :
- // exit loop
- gettingUserResponse = false;
- break;
-
- // all other controls in dialog are radio buttons
- default :
- // continue with loop
- gettingUserResponse = true;
-
- // if the radio button selection changed
- if ( currRadioButton != theItemHit )
- {
- // turn previous radio button off
- GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 0 );
-
- // turn current radio button on
- GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
- SetCtlValue( (ControlHandle) iHandle, 1 );
-
- // save current radio button choice
- currRadioButton = theItemHit;
- }
- break;
- }// switch
-
- }// while
-
- // get rid of the new dialog
- DisposDialog( theDialog );
-
- // select a value to return from this function according to
- // which radio button was selected in the dialog
- switch ( currRadioButton )
- {
- // return 0
- case( 2 ) : theStatus = kActionAtomResultContinue; // user selected return 0
- break;
-
- // return 1
- case( 3 ) : theStatus = kActionAtomResultCancel; // user selected return 1
- break;
-
- // return -1
- case( 4 ) : theStatus = kActionAtomResultFatalError;// user selected return -1
- break;
- }
-
- // return value selected by user in dialog
- return( theStatus );
-
- }
-
- // shoot one line of text out to the Wasabi Installer Debugger
- void PrintLine( ProcPtr pCallBackProcPtr, Str255 pParam0, Str255 pParam1, Str255 pParam2, Str255 pParam3 )
- {
- long theResult;
- RegisterScriptAction( pCallBackProcPtr, kDebuggingAction, kGenericDebugActID, pParam0, pParam1, pParam2, pParam3, &theResult );
- }
-
- // print a series of formatted lines describing the parameter block
- // received by the action atom out to the Wasabi Installer Debugger
- void PrintAAParamBlock( ActionAtom2PBPtr atomRecPtr )
- {
- Str255 numStr;
-
- PrintLine( atomRecPtr->fCallBackProcPtr, "\p\n", "\pParameter Block for Action Atom Format2...", "\p", "\p" );
-
- NumToString( atomRecPtr->fMessageID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\p", "\pfMessageID : ", numStr, "\p" );
-
- NumToString( (long) atomRecPtr->fStaticDataHdl, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfStaticDataHdl : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fTargetVRefNum, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfTargetVRefNum : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fTargetFolderDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfTargetFolderDirID : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fSystemVRefNum, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfSystemVRefNum : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fSystemBlessedDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfSystemBlessedDirID : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fRefCon, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfRefCon : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fDoingInstall, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfDoingInstall : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fDidLiveUpdate, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfDidLiveUpdate : ", numStr, "\p", "\p" );
-
- NumToString( (long) atomRecPtr->fInstallerTempDirID, numStr );
- PrintLine( atomRecPtr->fCallBackProcPtr, "\pfInstallerTempDirID : ", numStr, "\p", "\p\n" );
-
- }
-